package org.lys.web.exampletag;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;
public class Example1 extends SimpleTagSupport {

	String site;
	String page;
	
	@Override
	public void doTag() throws JspException, IOException {
		PageContext pageContext = (PageContext) this.getJspContext();
		HttpServletRequest request =  (HttpServletRequest) pageContext.getRequest();
		HttpServletResponse response =  (HttpServletResponse) pageContext.getResponse();
		
		String referer = request.getHeader("referer");
		if(referer==null||!referer.contains(site)){//不是来至指定的站点，跳转到page界面
			response.sendRedirect(request.getContextPath()+page);
		}
	
	}

	public void setSite(String site) {
		this.site = site;
	}

	public void setPage(String page) {
		this.page = page;
	}
}
